﻿using System.ComponentModel;
using Android.Content;
using JWXH.XH.components;
using JWXH.XH.Droid.components;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Application = Android.App.Application;
using Color = Android.Graphics.Color;

[assembly: ExportRenderer(typeof(ScrollViewNoBar), typeof(ScrollViewNoBarRender))]
namespace JWXH.XH.Droid.components
{
    public class ScrollViewNoBarRender : ScrollViewRenderer
    {
        public ScrollViewNoBarRender(Context context):base(context)
        {
            
        }
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources
                e.OldElement.PropertyChanged -= OnElementPropetyChanged;
            }

            if (e.NewElement != null)
            {
                // Configure the control and subscribe to event handlers 
                e.NewElement.PropertyChanged += OnElementPropetyChanged;
            }
        }

        private void OnElementPropetyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (ChildCount > 0)
            {
                //this.HorizontalScrollBarEnabled = false;
                GetChildAt(0).HorizontalScrollBarEnabled = false;
                GetChildAt(0).VerticalScrollBarEnabled = false;
            }

            this.HorizontalScrollBarEnabled = false;
            this.VerticalScrollBarEnabled = false;
        }
    }
}